/*****************************************************************************
** Notice:      Copyright (c) 2000 LSI Logic Corporation - All Rights Reserved
**
** File Name:   osp.h
**
** Revision:
**
** Date:        June, 2000
**
** Description: Operating System Portability (OSP) Layer public header. This
**              file is the public header file included by any driver, or
**              application file that needs to use the underlying RTOS
**              functionality. The definitions for the function prototypes in
**              this file can be found in the respective osp directory for
**              any RTOS supported.
*****************************************************************************/
#ifndef _OSP_H_
#define _OSP_H_                      /* Ensure osp.h is not included twice. */

#include "osmsg.h"
#include "event.h"

#define OSP_SUCCESS 0
#define TIM_SUCCESS 0
#define OSP_MSGQ_NO_WAIT       mp_Os_MSGQ_NO_WAIT
#define OSP_MSGQ_WAIT_FOREVER mp_Os_MSGQ_WAIT_FOREVER
#define DEF_MIN_STACK_SIZE   4*1024

/*****************************************************************************
** Timer tick interrupt period for the RTOS timer calls. All of the calls are
** in milli second resolution, but the lower bounds on the specified wait
** times are limited by the underlying timer interrupt rate. See the Timer
** driver, for more details on this issue.
** OSP_TIMER_TICK_INT_PERIOD - OSP Timer Tick Period in mSecs.
*****************************************************************************/
#define OSP_TIMER_TICK_INT_PERIOD     (10)

/*****************************************************************************
** Used in Nucleus Task Create. It denotes the maximum amount ot timer ticks
** that can expire while executing this task. A value of zero in this field
** disables time slicing for this task.
*****************************************************************************/
#define OSP_ONE_TIMER_TICK             (1)

/*****************************************************************************
** System definitions for SDP Task Priorities.
*****************************************************************************/
#define OSP_HIGHEST_PRIORITY           (99) /* Highest task priority. */
#define OSP_LOWEST_PRIORITY            (1)   /* Lowest task priority.  */

/*****************************************************************************
** Macros defining all generic errors possible in the OSP Layer. These
** values have been chosen so as to allow for any future additions.
** Note that most are warnings since they do not cause the system to crash.
** Any particular RTOS can return multiple errors and warnings for any
** particular system call to that RTOS. Such return codes tend to be RTOS
** specific. As such, it was not possible to generate a full suite of return
** codes that would accomodate all possible error codes, and warnings from
** all RTOS supported by the OSP Layer. In most cases, when the underlying
** RTOS system call returns a specific error, the OSP wrapper will simply
** return a FAILURE error code. In this case, it is the responsibility of the
** developer to anaylse the return code from the actual RTOS system call, to
** determine what was the exact error for that particular RTOS.
*****************************************************************************/
#define OSP_WARNING                    (10)
#define OSP_NO_BUFFERS_AVAILABLE       (20)
#define OSP_NO_MESSAGES_AVAILABLE      (30)
#define OSP_NO_MEMORY_AVAILABLE        (40)
#define OSP_NO_TOKENS_AVAILABLE        (50)
#define OSP_QUEUE_TIMEOUT              (60)
#define OSP_QUEUE_FULL                 (70)
#define OSP_SEMAPHORE_TIMEOUT          (80)
#define OSP_PERIOD_ROUNDED             (90)
#define OSP_INVALID_MEMORY_POINTER     (-30)

/*****************************************************************************
** The following macros are used by the application in conjunction with
** certain RTOS creation functions, to determine which of the waiting tasks
** will get the resource.
** WAIT_FIFO - First task to start waiting on the resource will get it.
** WAIT_PRIO - Task with the highest priority will get the resource.
*****************************************************************************/
#define WAIT_FIFO                      (0)
#define WAIT_PRIO                      (1)

/*****************************************************************************
** These macros are used by the application in conjunction with queue, and
** semaphore system calls to determine whether or not the task will block,
** when a requested resource is not available.
** TASK_NOWAIT - Do not wait for the resource.
** TASK_WAIT - Wait for the resource.
*****************************************************************************/
#define TASK_NOWAIT						(2)
#define TASK_WAIT						(3)
#define TIME_OUT_INFINITY				0

// define OSP task priority, 0 is lowest, 255 is highest
// generally, we use 0 ~ 64
#undef  MAX_USER_PRIORITY
#define MAX_USER_PRIORITY				(100 - 1)
#undef  MIN_USER_PRIORITY
#define MIN_USER_PRIORITY				0

#define FILTER_HIGHEST_PRIORITY			65
#define FILTERTIME_HIGHEST_PRIORITY		80
#define OSP_APP_MAINTASK_PRIORITY		70
#define OSP_MONITORPLAY_PRIORITY		70
#define OSP_PLAYTASK_PRIORITY		    70
#define OSP_MCUTASK_PRIORITY		    70
#define OSP_SAVETASK_PRIORITY		    70
#define OSP_STOCKTASK_PRIORITY			70
#define OSP_NWAPP_TASK_PRIORITY			70
#define OSP_UI_MAINTASK_PRIORITY		70
#define OSP_CAS_TASK_PRIORITY			70
#define OSP_DMDT_TASK_PRIORITY			80
#define OSP_FRSSHOW_TASK_PRIORITY		50
#define OSP_FRSCAN_TASK_PRIORITY		50
#define OSP_EPG_TASK_PRIORITY			60
#define OSP_PLAY_CTRL_TASK_PRIORITY		70
#define OSP_POST_TASK_PRIORITY			70
#define OSP_DMX_TASK_PRIORITY			70
#define OSP_IR_TASK_PRIORITY			90
#define OSP_PLAYER_TASK_PRIORITY		80
#define OSP_PLAYER_DMX_TASK_PRIORITY	80
#define OSP_AS_TASK_PRIORITY			60


#define OSP_QUEUE_WAIT_TIME				500  // 500 ms

/*****************************************************************************
** Queue Message Structure used by the OSP.
** Note that it was decided to use a structure for the message type so as to
** provide bounds checking on the message being placed in the queue. An array
** was the obvious alternative to such a structure, but it was felt that the
** array would not clearly indicate to the user the the limitations on the
** message size to use.
*****************************************************************************/
typedef struct
{
	U32 q1stWordOfMsg;                /* First word of a queue message.  */
	U32 q2ndWordOfMsg;                /* Second word of a queue message. */
	U32 q3rdWordOfMsg;                /* Third word of a queue message.  */
	U32 q4thWordOfMsg;                /* Fourth word of a queue message. */
} QUEUE_MESSAGE;

/*****************************************************************************
** Super BufferPool Control Block Structure used by the OSP. This allows us to
** conceal the pointer to the memory segment containing the BufferPool, and
** the actual BufferPool id, in one structure - referenced with a single
** handle.
** When deleting a BufferPool, is is also necessary to return the memory
** segment that was allocated to hold the BufferPool. In most RTOS, this
** involves two discrete steps. In this OSP, these two discrete steps are
** hidden from the user in the BufferPool create, and delete OSP calls.
** Note: The terms to describe a Buffer Pool differs from RTOS to RTOS. Some
** refer to them as partitions, some ring buffers, and some simply buffer
** pools. The term 'BufferPool' was chosen as it seemed to indicate best,
** the nature of the object being created.
*****************************************************************************/
typedef struct
{
  U32 *rtosPartitionId;             /* Id of RTOS BufferPool. */
  void *ptrToSegToHoldPartn;           /* Pointer to  memory segment. */
} OSP_PARTITION_CTRL_BLK;

/*****************************************************************************
** OSP API Prototypes.
** This is the only set from which operating system functionality can be used
** by the application. If the functionality required does not exist here, it
** is necessary to redesign the application so that the functionality offered
** below will suffice.
*****************************************************************************/

/*****************************************************************************
** Queue OSP Prototypes - task-task, isr-task message passing.
*****************************************************************************/
S32 OSPQueueCreate(char name[], U32 maxQueueLength, U32 taskWaitMode,
                     U32 *queueId);
S32 OSPQueueDelete(U32 queueId);
S32 OSPQueueGetMessage(U32 queueId, T_FTAEvent *message,
                         U32 waitMode, U32 milliSec2Wait);
S32 OSPQueueSendMessage(U32 queueId, T_FTAEvent *message,int wait_mode);

/*****************************************************************************
** Region OSP Prototypes - variable memory segment allocation.
*****************************************************************************/
void    *OSPMalloc(U32 numberOfBytes);
S32 OSPFree(void *ptrToSegment);

/*****************************************************************************
** Semaphore OSP Prototypes - resource protection, and synchronization.
*****************************************************************************/
S32 OSPSemaphoreCreate(char name[], U32 initialTokenCount,
                         U32 taskWaitMode, U32 *semaphoreId);
S32 OSPSemaphoreDelete(U32 semaphoreId);
S32 OSPSemaphoreGetToken(U32 semaphoreId, U32 waitMode,
                           U32 milliSec2Wait);
S32 OSPSemaphoreReturnToken(U32 semaphoreId);

/*****************************************************************************
** Task OSP Prototypes - task creation, control, and deletion.
*****************************************************************************/
S32 OSPTaskCreate(char name[], U32 stackSize, void (*entryPoint)(),
                    S32 priority, U32 arg1, U32 arg2, U32 *taskId);
S32 OSPTaskDelete(U32 taskId);
S32 OSPTaskTemporarySleep(U32 milliSec2Wait);



/*****************************************************************************
** OSP Initialization API - called during application initialization.
*****************************************************************************/
S32 OSPInitialize(void);   /* Called by the application, initializes the timer. */
void    taskDelay (S32 ticks);
void    task_lockcreat(void);
void    EXCEndCriticalSection(S32 state);
void    EXCEndCriticalSection(S32 state);
void    task_lock(void);
void    task_unlock(void);



#endif  /*_OSP_H_*/                       /* End of conditional include. */









